package com.atguigu.study.resp;

import lombok.Getter;

import java.util.Arrays;

/**
 * @author:高尚
 * @data:2025/7/31 9:43
 * @description:
 */
public enum TrafficLight {
    //举值
    RED("1","红灯"),
    GREEN("2","绿灯"),
    YELLOW("3","黄灯");

    //构造
    @Getter
    private String code;
    @Getter
    private String message;
    TrafficLight(String code, String message){
        this.code = code;
        this.message = message;
    }


    //遍历
    public static TrafficLight getTrafficLight(String code){
        for (TrafficLight enemElement : TrafficLight.values()) {
            if(code.equalsIgnoreCase(enemElement.getCode())){
                return enemElement;
            }
        }
        return null;
    }

    public static TrafficLight getTrafficLightV2(String code){
        return Arrays.stream(TrafficLight.values()).filter(x->x.getCode().equalsIgnoreCase(code)).findFirst().orElse(null);
    }

    public static void main(String[] args) {
        System.out.println(getTrafficLight("3"));
        System.out.println(getTrafficLightV2("1"));
        System.out.println(TrafficLight.RED);
        System.out.println(TrafficLight.RED.getCode());
        System.out.println(TrafficLight.GREEN.getMessage());
//        for (TrafficLight value : TrafficLight.values()) {
//            System.out.println("value = " + value);
//            System.out.println(value.getCode()+"...."+value.getMessage());
//        }
//        System.out.println(TrafficLight.valueOf("RED"));
    }

}
